package com.base.myproject.client.tools.fileupload;

import com.extjs.gxt.ui.client.widget.ProgressBar;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class BaseProgressX extends BasicProgress {
	VerticalPanel cp = new VerticalPanel();
	ProgressBar pb = new ProgressBar();
	public BaseProgressX() {
		//super();
		
		cp.add(pb);
		
		cp.add(super.getWidget());
		cp.layout();
	}
	@Override public Widget getWidget() {
//		//return new HTML();
//		ContentPanel cp = new ContentPanel();
	//	panel.setHeaderVisible(false);
		
		return cp;
	//	return BaseProgressBar.getinstance();
	};
	
	
	public void setStatus(int stat) {
		
	
		assert stat >= 0 && stat <= 4;
    statusLabel.removeStyleDependentName("" + status);
		status = stat;
    statusLabel.addStyleDependentName("" + status);
    switch (status) {
      case QUEUED:
        updateStatusPanel(true, MSG_QUEUED);
        break;
      case INPROGRESS:
        updateStatusPanel(false, MSG_INPROGRESS);
        break;
      case FINISHED:
        updateStatusPanel(true, MSG_FINISHED);
        break;
      case ERROR:
        updateStatusPanel(true, MSG_ERROR);
        break;
    }
  }
	  protected void updateStatusPanel(boolean hasFinished, String message) {
		  System.out.println(message);
		  	if (prg != null) {
		      prg.setVisible(!hasFinished);
		      fileNameLabel.setVisible(hasFinished);
		      statusLabel.setVisible(hasFinished);
		  	} else if (status == INPROGRESS) {
					message += "(" + percent + "%)";
					 pb.updateProgress(percent%100*0.01, percent+"%");
		  	}
		  	else if (status == FINISHED) {
				
				pb.updateProgress(1, "完成");
				pb.setVisible(false);
				 statusLabel.setText(message);
	  	}
		   // statusLabel.setText(percent+"");
		   
		  }

		public IUploadStatus newInstance() {
			return new BaseProgressX();
		}
}
